﻿using System;
using System.Windows;
using System.Windows.Data;

namespace AnthStat.WPF.Applications.Converters
{
    public sealed class AgeAndReferenceToVisibilityConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // TODO: Code contracts

            if (values.Length != 2)
            {
                return System.Windows.Visibility.Collapsed;
            }
            if (values[0] == null || values[0] == DependencyProperty.UnsetValue)
            {
                return System.Windows.Visibility.Collapsed;
            }

            double ageMonths = (double)values[0];
            string applicationGrowthReference = values[1].ToString();
            string objectGrowthReference = parameter.ToString();
            //string objectIndicator = values[2].ToString();

            if (!applicationGrowthReference.Equals(objectGrowthReference, StringComparison.OrdinalIgnoreCase))
            {
                return System.Windows.Visibility.Collapsed;
            }
            else
            {
                if (applicationGrowthReference.Equals("WHO", StringComparison.OrdinalIgnoreCase) && ageMonths > 60)
                {
                    //if (objectIndicator.Equals("SSF", StringComparison.OrdinalIgnoreCase) || 
                    //    objectIndicator.Equals("TSF", StringComparison.OrdinalIgnoreCase) || 
                    //    objectIndicator.Equals("MUAC", StringComparison.OrdinalIgnoreCase) || 
                    //    objectIndicator.Equals("HC", StringComparison.OrdinalIgnoreCase)
                    //    )
                    //{
                        return System.Windows.Visibility.Collapsed;
                    //}
                }

                return System.Windows.Visibility.Visible;
            }

        }

        public object[] ConvertBack(object values, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
